class Solution {

public:
    int divide(int dividend, int divisor) {
        
        int flg=1;
        if(dividend<0){
            flg=-flg;
        }
        if(divisor<0){
            flg=-flg;
        }

        long long sum=abs(static_cast<long long>(dividend));
        long long minus=abs(static_cast<long long>(divisor));
        long long nRet=0;
        while(sum>=minus){
            long long pos=1;
            long long  mi=minus;
            while(sum>=mi){
                sum-=mi;
                nRet+=pos;
                pos<<=1;
                mi<<=1;
            }
        }
        if(flg<0){
            nRet=-nRet;
        }
        if(nRet>INT_MAX){
            return INT_MAX;
        }
        if(nRet<INT_MIN){
            return INT_MIN;
        }

        return nRet;
    }
};
